package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.BuildingListBean;
import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.CommentView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 * 楼宇添加/更新/删除
 */
public class BuildingAddPest {

    private CommentView commentView;

    public BuildingAddPest(CommentView commentView) {
        this.commentView=commentView;
    }


    /**
     *
     * @param orgId 组织id
     * @param builddatasId 楼宇主键
     * @param detailBean 详情
     * @param url url
     */
    public void addBuilding(String orgId, String builddatasId,BuildingListBean.RowsBean detailBean, String url){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("builddatas.organization.id", orgId);//网格
        map.put("builddatas.id", builddatasId);
        map.put("builddatas.buildingname", detailBean.getBuildingname());
        map.put("builddatas.type.id", detailBean.getType()!=null?detailBean.getType().getId():"");//网格
        map.put("builddatas.buildingaddress",detailBean.getBuildingaddress());
        map.put("builddatas.buildingstructures.id", detailBean.getBuildingstructures()!=null?
                detailBean.getBuildingstructures().getId():"");
        map.put("builddatas.owner", detailBean.getOwner());
        map.put("builddatas.responsibleperson", detailBean.getResponsibleperson());
        map.put("builddatas.phone", detailBean.getPhone());//网格
        new CollectManager().addBuilding(url,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                commentView.commentSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                commentView.showError(message);
            }
        });
    }

    /**
     * 删除
     * @param id 楼宇主键
     */
    public void deleteBuilding(String id){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("id", id);//楼宇主键
        new CollectManager().deleteBuilding(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                commentView.commentSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                commentView.showError(message);
            }
        });
    }
}
